package encryptedDemo

import (
	"crypto/hmac"
	"crypto/sha1"
	"fmt"
	"net/url"
	"sort"
	"strings"
)

// 对http请求的query进行token认证
func encrypt(params url.Values, appkey string){
	//先对query排序
	sortKeyArr := []string{}
	for key,_ := range params {
		if key != "signa..."{
			sortKeyArr = append(sortKeyArr,key)
		}
	}
	sort.Strings(sortKeyArr)

	query := ""
	for _,k := range sortKeyArr {
		query = query +fmt.Sprintf("%s=%s&",k,params[k][0])
	}
	query = strings.TrimSuffix(query,"&")

	mac := hmac.New(sha1.New,[]byte(appkey))
	mac.Write([]byte(query))
	var sign = fmt.Sprintf("%X",mac.Sum(nil))
	fmt.Println(sign)
}
